#include <unicode/brkiter.h>

using namespace icu;

int main(int argc, char **argv)
{
    std::string breakingText = "Quick brown fox jumps over the lazy dog";
    if (argc > 1) {
        breakingText = argv[1];
    }
    printf("Breaking Text: %s\n", breakingText.c_str());

    UErrorCode errcode = U_ZERO_ERROR;
    const auto &locale = Locale::getDefault();
    auto wb = BreakIterator::createWordInstance(locale, errcode);
    if (wb == nullptr) {
        printf("BreakIterator create failed\n");
        return 1;
    }
    wb->setText(breakingText.c_str());

    for (int beg = wb->first(), end = wb->next();
         end != wb->DONE;
         beg = end, end = wb->next()) {
        printf("- '%s'\n", breakingText.substr(beg, end - beg).c_str());
    }

    delete wb;
    return 0;
}
